package com.util;

public class InUtil {
	
	public static StringBuffer getIn(long[] ids,String key,int size){
    	StringBuffer sb=new StringBuffer();
    	int num=ids.length%size==0?ids.length/size:ids.length/size+1;
    	//System.out.println("num:"+num);
    	sb.append(" (");
    	for(int i=0;i<num;i++){
    		//System.out.println("i:"+i);
    		int bound;
    		if(i==num-1){
    			bound=i*size+(ids.length-(num-1)*size);
    			System.out.println(bound);
    		}else{
    			bound=(i+1)*size;
    		}
    		//System.out.println("bound:"+bound);
    		sb.append(" "+key+" in (");
    		for(int j=i*size;j<bound;j++){
    			sb.append(ids[j]+",");
    		}
    		sb.deleteCharAt(sb.lastIndexOf(",")).append(") or");
    	}
    	sb.deleteCharAt(sb.lastIndexOf("o"));
    	sb.deleteCharAt(sb.lastIndexOf("r"));
    	sb.deleteCharAt(sb.lastIndexOf(" "));
    	sb.append(") ");
    	return sb;
    }
	public static StringBuffer getIn(int[] ids,String key,int size){
    	StringBuffer sb=new StringBuffer();
    	int num=ids.length%size==0?ids.length/size:ids.length/size+1;
    	//System.out.println("num:"+num);
    	sb.append(" (");
    	for(int i=0;i<num;i++){
    		//System.out.println("i:"+i);
    		int bound;
    		if(i==num-1){
    			bound=i*size+(ids.length-(num-1)*size);
    		}else{
    			bound=(i+1)*size;
    		}
    		//System.out.println("bound:"+bound);
    		sb.append(" "+key+" in (");
    		for(int j=i*size;j<bound;j++){
    			sb.append(ids[j]+",");
    		}
    		sb.deleteCharAt(sb.lastIndexOf(",")).append(") or");
    	}
    	sb.deleteCharAt(sb.lastIndexOf("o"));
    	sb.deleteCharAt(sb.lastIndexOf("r"));
    	sb.deleteCharAt(sb.lastIndexOf(" "));
    	sb.append(") ");
    	return sb;
    }
	public static StringBuffer getIn(String[] ids,String key,int size){
    	StringBuffer sb=new StringBuffer();
    	int num=ids.length%size==0?ids.length/size:ids.length/size+1;
    	//System.out.println("num:"+num);
    	//sb.append(" (");
    	for(int i=0;i<num;i++){
    		//System.out.println("i:"+i);
    		int bound;
    		if(i==num-1){
    			bound=i*size+(ids.length-(num-1)*size);
    		}else{
    			bound=(i+1)*size;
    		}
    		//System.out.println("bound:"+bound);
    		sb.append(" "+key+" in (");
    		for(int j=i*size;j<bound;j++){
    			sb.append(ids[j]+",");
    		}
    		sb.deleteCharAt(sb.lastIndexOf(",")).append(" or");
    	}
    	sb.deleteCharAt(sb.lastIndexOf("o"));
    	sb.deleteCharAt(sb.lastIndexOf("r"));
    	sb.deleteCharAt(sb.lastIndexOf(" "));
    	sb.append(") ");
    	return sb;
    }
	
	public static StringBuffer getIn_str(String[] ids,String key,int size){
    	StringBuffer sb=new StringBuffer();
    	int num=ids.length%size==0?ids.length/size:ids.length/size+1;
    	//System.out.println("num:"+num);
    	//sb.append(" (");
    	for(int i=0;i<num;i++){
    		//System.out.println("i:"+i);
    		int bound;
    		if(i==num-1){
    			bound=i*size+(ids.length-(num-1)*size);
    		}else{
    			bound=(i+1)*size;
    		}
    		//System.out.println("bound:"+bound);
    		sb.append(" "+key+" in (");
    		for(int j=i*size;j<bound;j++){
    			sb.append("'"+ids[j]+"'"+",");
    		}
    		sb.deleteCharAt(sb.lastIndexOf(",")).append(" or");
    	}
    	sb.deleteCharAt(sb.lastIndexOf("o"));
    	sb.deleteCharAt(sb.lastIndexOf("r"));
    	sb.deleteCharAt(sb.lastIndexOf(" "));
    	sb.append(") ");
    	return sb;
    }
	
	public static StringBuffer getIn(Object[] ids,String key,int size){
    	StringBuffer sb=new StringBuffer();
    	int num=ids.length%size==0?ids.length/size:ids.length/size+1;
    	//System.out.println("num:"+num);
    	sb.append(" (");
    	for(int i=0;i<num;i++){
    		//System.out.println("i:"+i);
    		int bound;
    		if(i==num-1){
    			bound=i*size+(ids.length-(num-1)*size);
    		}else{
    			bound=(i+1)*size;
    		}
    		//System.out.println("bound:"+bound);
    		sb.append(" "+key+" in (");
    		for(int j=i*size;j<bound;j++){
    			sb.append(ids[j]+",");
    		}
    		sb.deleteCharAt(sb.lastIndexOf(",")).append(") or");
    	}
    	sb.deleteCharAt(sb.lastIndexOf("o"));
    	sb.deleteCharAt(sb.lastIndexOf("r"));
    	sb.deleteCharAt(sb.lastIndexOf(" "));
    	sb.append(") ");
    	return sb;
    }
	public static boolean contains(int[] arrs,int key){
		for(int i:arrs){
			if(i==key)
				return true;
		}
		return false;
	}
	public static boolean contains(long[] arrs,long key){
		for(long i:arrs){
			if(i==key)
				return true;
		}
		return false;
	}
	
	public static StringBuffer getIN(Object[] ids,String key,int size){
    	StringBuffer sb=new StringBuffer();
    	int num=ids.length%size==0?ids.length/size:ids.length/size+1;
    	//System.out.println("num:"+num);
    	for(int i=0;i<num;i++){
    		//System.out.println("i:"+i);
    		int bound;
    		if(i==num-1){
    			bound=i*size+(ids.length-(num-1)*size);
    		}else{
    			bound=(i+1)*size;
    		}
    		//System.out.println("bound:"+bound);
    		sb.append(" "+key+" in (");
    		for(int j=i*size;j<bound;j++){
    			sb.append(ids[j]+",");
    		}
    		sb.deleteCharAt(sb.lastIndexOf(",")).append(") or");
    	}
    	sb.deleteCharAt(sb.lastIndexOf("o"));
    	sb.deleteCharAt(sb.lastIndexOf("r"));
    	sb.deleteCharAt(sb.lastIndexOf(" "));
    	return sb;
    }
}
